/****************************************************************************
 * Elisa 1.0                                                                *
 *--------------------------------------------------------------------------*
 * Author: Laurent Granvilliers, Vincent Sorin                              *
 * Copyright (c) 2004 Laboratoire d'Informatique de Nantes Atlantique       *
 *--------------------------------------------------------------------------*
 * Elisa is distributed WITHOUT ANY WARRANTY. Read the associated           *
 * COPYRIGHT file for more details.                                         *
 *--------------------------------------------------------------------------*
 * elisa_real_constant.cpp                                                  *
 ****************************************************************************/

#include <sstream>
#include "elisa_real_constant.h"

USING_ELISA
//--------------------------------------------------------------------------
// class RealConstant
//--------------------------------------------------------------------------


RealConstant::~RealConstant()
{
	delete _value;
}


//## Other Operations (implementation)
void RealConstant::print(std::ostream & o) const
{
	_value->print(o);
}

double RealConstant::getValue() const
{
	return _value->getValue();
}

Interval RealConstant::getInterval() const
{
	return _value->getInterval();
}


//--------------------------------------------------------------------------
// class IntervalConstant
//--------------------------------------------------------------------------


IntervalConstant::~IntervalConstant()
{
	delete _inf;
	delete _sup;
}


//## Other Operations (implementation)
void IntervalConstant::print(std::ostream & o) const
{
	o << "[";
	_inf->print(o);
	o << ",";
	_sup->print(o);
	o << "]";
}

double IntervalConstant::getInf() const
{
	return _inf->getValue();
}

double IntervalConstant::getSup() const
{
	return _sup->getValue();
}

Interval IntervalConstant::getInterval() const
{
	return Interval(_inf->getValue(), _sup->getValue());
}

//--------------------------------------------------------------------------
// class ConstFloat
//--------------------------------------------------------------------------


ConstFloat::~ConstFloat()
{
}


void ConstFloat::print(std::ostream & o) const
{
	o << _val;
}


double ConstFloat::getValue() const
{
	return _val;
}

Interval ConstFloat::getInterval() const
{
	return Interval(_val);
}

ConstRationnal::~ConstRationnal()
{
}


void ConstRationnal::print(std::ostream & o) const
{
	o << "(" << _num << "/" << _den << ")";
}


double ConstRationnal::getValue() const
{
	return (double)_num / (double)_den;
}

Interval ConstRationnal::getInterval() const
{
	return Interval(_num) / Interval(_den);
}

ConstString::~ConstString()
{
}


void ConstString::print(std::ostream & o) const
{
	o << "(" << _val << ")";
}


double ConstString::getValue() const
{
	/*
	const char *temp = _val.c_str();
	double result = atof(temp);
	delete temp;
	*/
	double result;
	std::istringstream iss(_val); iss >> result;
	return result;
}

Interval ConstString::getInterval() const
{
	double result;
	std::istringstream iss(_val); iss >> result;
	return Interval(result);
}

ConstInt::~ConstInt()
{
}


void ConstInt::print(std::ostream & o) const
{
	o << "(" << _val << ")";
}


double ConstInt::getValue() const
{
	return (double)_val;
}

Interval ConstInt::getInterval() const
{
	return Interval(_val);
}
